﻿using BCDto.TMS.MoveHouseConfig.MoveHouseConfig;
using BCDto.TMS.MoveHouseConfig.MoveHouseSpecificationConfig;
using BCDto.TMS.MoveHouseConfig.MoveHouseSpecificationServiceConfig;
using BCService.TMS.MoveHouseConfig.MoveHouseConfig;
using BCService.TMS.MoveHouseConfig.MoveHouseSpecificationConfig;
using BCService.TMS.MoveHouseConfig.MoveHouseSpecificationServiceConfig;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace BCTMSRESTful.Controllers.ClientApp.MoveHouseConfig
{
    /// <summary>
    /// 搬家配置
    /// </summary>
    [ApiExplorerSettings(GroupName = "ClientApp")]
    [Route("api/v1/ClientApp/[controller]")]
    public class MoveHouseConfigController : ClientAppBaseController
    {
        private readonly IMoveHouseConfigService moveHouseConfigService;
        private readonly IMoveHouseSpecificationConfigService moveHouseSpecificationConfigService;
        private readonly IMoveHouseSpecificationServiceConfigService moveHouseSpecificationServiceConfigService;
        public MoveHouseConfigController(IMoveHouseConfigService moveHouseConfigService,
            IMoveHouseSpecificationConfigService moveHouseSpecificationConfigService,
            IMoveHouseSpecificationServiceConfigService moveHouseSpecificationServiceConfigService)
        {
            this.moveHouseConfigService = moveHouseConfigService;
            this.moveHouseSpecificationConfigService = moveHouseSpecificationConfigService;
            this.moveHouseSpecificationServiceConfigService = moveHouseSpecificationServiceConfigService;
        }

        /// <summary>
        /// 获取搬家配置
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseConfigViewDto>), 200)]
        public IActionResult GetList(
            [FromQuery(Name = "county_code")] string countyCode)
        {
            var result = this.moveHouseConfigService.GetAllClientList(countyCode);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取代理商搬家规格
        /// </summary>
        /// <param name="moveHouseConfigId">搬家配置id</param>
        /// <param name="countyCode"></param>
        /// <returns></returns>
        [HttpGet("[action]/{move_house_config_id}")]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseSpecificationConfigClientDto>), 200)]
        public IActionResult GetSpecification([FromRoute(Name = "move_house_config_id")] long moveHouseConfigId,
            [FromQuery(Name = "county_code")] string countyCode)
        {
            var result = this.moveHouseSpecificationServiceConfigService.GetSpecification(moveHouseConfigId, countyCode);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取代理商搬家价格
        /// </summary>
        /// <param name="moveHouseConfigId">搬家配置id</param>

        /// <param name="countyCode"></param>
        /// <returns></returns>
        [HttpGet("[action]/{move_house_config_id}")]
        [ProducesResponseType(typeof(IEnumerable<MoveHouseSpecificationServiceConfigPriceClientDto>), 200)]
        public IActionResult GetPrice([FromRoute(Name = "move_house_config_id")] long moveHouseConfigId,
            [FromQuery(Name = "county_code")] string countyCode
            )
        {
            long? agentRecordId = this.GetAgentRecordIdByCountyCode(countyCode);
            var result = this.moveHouseSpecificationServiceConfigService.GetPrice(moveHouseConfigId, agentRecordId, countyCode);
            return this.Ok(result);
        }
    }
}
